#ifndef DATAIMPORTER_H
#define DATAIMPORTER_H

#include <QObject>
#include <QSqlDatabase>
#include <QString>
#include <QMap>

class DataImporter : public QObject
{
    Q_OBJECT

public:
    explicit DataImporter(QObject *parent = nullptr);
    
    enum ImportFormat {
        CSV,
        JSON,
        XML,
        SQL
    };
    Q_ENUM(ImportFormat)
    
    bool importFile(const QString &filename, const QString &tableName, 
                    ImportFormat format, const QSqlDatabase &db);
    
signals:
    void importProgress(int percentage);
    void importFinished(const QString &message);
    void importError(const QString &error);

private:
    bool importFromCSV(const QString &filename, const QString &tableName, const QSqlDatabase &db);
    bool importFromJSON(const QString &filename, const QString &tableName, const QSqlDatabase &db);
    bool importFromXML(const QString &filename, const QString &tableName, const QSqlDatabase &db);
    bool importFromSQL(const QString &filename, const QString &tableName, const QSqlDatabase &db);
    
    QStringList parseCSVLine(const QString &line) const;
    QString unescapeCSVField(const QString &field) const;
    
    bool createTableFromCSV(const QString &filename, const QString &tableName, const QSqlDatabase &db);
    bool createTableFromJSON(const QString &filename, const QString &tableName, const QSqlDatabase &db);
};

#endif // DATAIMPORTER_H